<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>系统菜单管理</title>
    <meta name="description" content="">
    <meta name="keywords" content="index">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="icon" type="image/png" href="/resources/i/favicon.png">
    <link rel="apple-touch-icon-precomposed" href="/resources/i/app-icon72x72@2x.png">
    <meta name="apple-mobile-web-app-title" content="Amaze UI"/>
    <script src="/resources/js/echarts.min.js"></script>
    <link rel="stylesheet" href="/resources/css/amazeui.min.css"/>
    <link rel="stylesheet" href="/resources/css/amazeui.datatables.min.css"/>
    <link rel="stylesheet" href="/resources/css/app.css">
    <link rel="stylesheet" href="/resources/css/employee.type.css">
    <script src="/resources/js/jquery.min.js"></script>

</head>

<body data-type="widgets">
<script src="/resources/js/theme.js"></script>
<div class="am-g tpl-g">
    <%--头部开始--%>
    <%@include file="header.jsp" %>
    <%--头部结束--%>

    <!-- 内容区域 -->
    <div class="tpl-content-wrapper">

        <div class="container-fluid am-cf">
            <div class="row">
                <div class="am-u-sm-12 am-u-md-12 am-u-lg-9">
                    <div class="page-header-heading"><span class="am-icon-home page-header-heading-icon"></span> 进货管理
                        <small>Application For Incoming Goods</small>
                    </div>
                    <p class="page-header-description">进货单管理</p>
                </div>
                <div class="am-u-lg-3 tpl-index-settings-button">
                    <%--<button type="button" class="page-header-button"--%>
                    <%--data-am-modal="{target:'#type-model',width:600}"><span--%>
                    <%--class="am-icon-paint-brush">添加一级菜单</span></button>--%>
                </div>
            </div>

        </div>

        <div class="row-content am-cf">
            <div class="row widget  am-cf" id="content">
                <!--<div class="am-u-md-1  am-u-lg-2"></div>-->
                <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                    <%--新的菜单模式--%>

                    <table width="100%" class="am-table am-table-bordered am-table-compact tpl-table-black "
                           id="example-r">
                        <caption>进货申请列表</caption>
                        <thead>
                        <tr>
                            <th>序号</th>
                            <th>申请店名</th>
                            <th>申请人</th>
                            <th>申请状态</th>
                            <th>总价</th>
                            <th>联系电话</th>
                            <th>进货日期</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <c:forEach items="${pageInfo.list}" var="p" varStatus="i">
                        <tr>
                            <td>${i.index+1}</td>
                            <td>${p.branName}</td>
                            <td>${p.aplicman}</td>
                            <td>
                                <c:choose>
                                    <c:when test="${p.aplicState==0}">等待处理</c:when>
                                    <c:when test="${p.aplicState==1}">等待发货</c:when>
                                    <c:when test="${p.aplicState==2}">已发货</c:when>
                                    <c:when test="${p.aplicState==3}">订单完成</c:when>
                                    <c:when test="${p.aplicState==4}">订单撤销</c:when>
                                    <c:otherwise>状态异常</c:otherwise>
                                </c:choose>
                            </td>
                            <td>${p.purchPrice}</td>
                            <td>${p.aplictel}</td>
                            <td><fmt:formatDate type="both" value="${p.aplicDate}"/></td>
                            <td>
                                <div class="tpl-table-black-operation">
                                    <c:choose>
                                        <c:when test="${p.aplicState==0}">
                                            <a href="javascript:editType('${p.id}');">
                                                <i class="am-icon-pencil"></i> 发货
                                            </a>
                                        </c:when>
                                        <c:when test="${p.aplicState==1}">
                                            <a href="javascript:editType('${p.id}');">
                                                <i class="am-icon-pencil"></i> 发货
                                            </a>
                                            <a style="color: red" href="javascript:updateType('${p.id}',4);">
                                                <i class="am-icon-stop"></i> 撤销订单
                                            </a>&nbsp;&nbsp;
                                          </c:when>
                                        <c:when test="${p.aplicState==2}">已发货</c:when>
                                        <c:when test="${p.aplicState==3}">订单结束</c:when>
                                        <c:when test="${p.aplicState==4}">订单撤销
                                        </c:when>
                                        <c:otherwise>状态异常</c:otherwise>
                                    </c:choose>


                                    <a href="javascript:seeMenu('${p.id}');">
                                        <i class="am-icon-pencil"></i> 查看进货单
                                    </a>
                                    <a href="javascript:hiddenMenu();">
                                        <i class="am-icon-pencil"></i> 隐藏进货单
                                    </a>
                                        <%-- <a href="javascript:getPermisson('${smenu.id}');">
                                             <i class="am-icon-pencil"></i> 授权
                                         </a>--%>
                                        <%--<a href="javascript:addSecondMenu('${smenu.id}');">--%>
                                        <%--<i class="am-icon-pencil"></i> 添加子菜单--%>
                                        <%--</a>--%>
                                </div>
                            </td>
                        </tr>

                        </c:forEach>

                    </table>
                        <!-- 分页开始 -->
                        <div class="am-u-lg-12 am-cf paging">

                            <!-- 分页文字信息，其中分页信息都封装在pageInfo中 -->
                            <div class="col-md-6">
                                当前第：${pageInfo.pageNum }页，总共：${pageInfo.pages }页，总共：${pageInfo.total }条记录
                            </div>
                            <div class="am-fr">
                                <ul class="am-pagination tpl-pagination">
                                    <!-- 首页 -->
                                    <li><a href="/stockManageController/getstock?pn=1">首页</a></li>
                                    <!-- 上一页 -->
                                    <c:if test="${pageInfo.hasPreviousPage }">
                                        <li>
                                            <a href="/stockManageController/getstock?pn=${pageInfo.pageNum-1 }" aria-label="Previous">
                                                <span aria-hidden="true">&laquo;</span>
                                            </a>
                                        </li>
                                    </c:if>
                                    <!-- 循环遍历连续显示的页面，若是当前页就高亮显示，并且没有链接 -->
                                    <c:forEach items="${pageInfo.navigatepageNums }" var="page_Num">
                                        <c:if test="${page_Num == pageInfo.pageNum }">
                                            <li class="am-active"><a href="/stockManageController/getstock?pn=${page_Num }">${page_Num }</a></li>
                                        </c:if>
                                        <c:if test="${page_Num != pageInfo.pageNum }">
                                            <li><a href="/stockManageController/getstock?pn=${page_Num }">${page_Num }</a></li>
                                        </c:if>
                                    </c:forEach>
                                    <!-- 下一页 -->
                                    <c:if test="${pageInfo.hasNextPage }">
                                        <li>
                                            <a href="/stockManageController/getstock?pn=${pageInfo.pageNum+1 }" aria-label="Next">
                                                <span aria-hidden="true">&raquo;</span>
                                            </a>
                                        </li>
                                    </c:if>
                                    <!-- 末页 -->
                                    <li><a href="/stockManageController/getstock?pn=${pageInfo.pages }">末页</a></li>
                                </ul>
                            </div>
                        </div>
                        <!-- 分页结束 -->
                    <table width="100%" class="am-table am-table-bordered am-table-compact tpl-table-black"
                           id="secondTable" style="display: none">
                        <caption>进货清单</caption>
                        <thead>
                        <tr>
                            <th>序号</th>
                            <th>商品名称</th>
                            <th>进货总价</th>
                            <th>单价</th>
                            <th>现有库存</th>
                            <th>进货数量</th>
                            <th>说明</th>
                        </tr>
                        </thead>
                        <tbody>
                        <%--<tr>--%>
                        <%--<td>1</td>--%>
                        <%--<td>2</td>--%>
                        <%--<td>3</td>--%>
                        <%--<td>--%>
                        <%--<div class="tpl-table-black-operation">--%>
                        <%--<a href="javascript:editType('${type.emTypeId}');">--%>
                        <%--<i class="am-icon-pencil"></i> 编辑--%>
                        <%--</a>--%>
                        <%--</div>--%>

                        <%--</td>--%>
                        <%--</tr>--%>
                        </tbody>
                    </table>

                </div>
                <!--分页插件Start-->
                <div class="am-u-lg-12 am-cf paging">

                </div>
            </div>
        </div>
    </div>


    <div class="am-modal tpl-am-model-bd" id="type-model">
        <div class="am-modal-dialog">
            <div class="am-modal-hd row">
                <h2>一级菜单管理</h2><a href="javascript: void(0)" class="am-close am-close-spin"
                                  data-am-modal-close>&times;</a>
            </div>
            <input type="hidden" id="fristid">
            <div class="am-u-sm-3 am-u-lg-2">菜单名称</div>
            <div class="am-u-sm-9  am-u-lg-10 modal-input-div">
                <input type="text" id="fristName" name="fristName" placeholder="请输入英文字母" class="am-form-field" required>
            </div>
            <div class="am-u-sm-3 am-u-lg-2">菜单图标</div>
            <div class="am-u-sm-8 am-u-lg-9 modal-input-div">
                <input type="text" id="fristicon" name="typeInstruct" placeholder="请输入汉字" class="am-form-field"
                       required/>
            </div>
            <div class="am-u-sm-1 am-u-lg-1 modal-input-div" id="fristIconDiv"></div>
            <button type="button" id="fristAddBtn" class=" am-u-md-12  am-btn am-btn-primary" style="margin-top: 10px">
                添加
            </button>
        </div>
    </div>

    <div class="am-modal tpl-am-model-bd" id="seconde-type-model">
        <div class="am-modal-dialog">
            <div class="am-modal-hd row">
                <h2>二级菜单管理</h2><a href="javascript: void(0)" class="am-close am-close-spin"
                                  data-am-modal-close>&times;</a>
            </div>
            <input type="hidden" id="secondeId">
            <div class="am-u-sm-3 am-u-lg-2">名称</div>
            <div class="am-u-sm-9  am-u-lg-10 modal-input-div">
                <input type="text" id="secondeName" name="secondeName" placeholder="请输入汉字" class="am-form-field"
                       required>
            </div>
            <div class="am-u-sm-3 am-u-lg-2">链接</div>
            <div class="am-u-sm-9 am-u-lg-10 modal-input-div">
                <input type="text" id="secondeUrl" name="secondeUrl" placeholder="请输入链接" class="am-form-field"
                       readonly/>
            </div>
            <button type="button" id="secondeAddBtn" onclick="updateSecondMenu()"
                    class=" am-u-md-12  am-btn am-btn-primary" style="margin-top: 10px">添加
            </button>
        </div>
    </div>

    <div class="am-modal tpl-am-model-bd" id="promission-type-model">
        <div class="am-modal-dialog">
            <div class="am-modal-hd row">
                <h2>请选择岗位授权</h2><a href="javascript: void(0)" class="am-close am-close-spin"
                                   data-am-modal-close>&times;</a>
            </div>
            <%--<form action="/u/type" method="post">--%>
            <input type="hidden" id="menuId">
            <div class="am-u-sm-3 am-u-lg-2">名称</div>
            <div class="am-u-sm-9  am-u-lg-10 modal-input-div">
                <select id="menudetali" data-am-selected="{btnSize: 'sm'}">
                    <%--<option value="option1">所有类别</option>--%>
                    <%--<option value="option2">IT业界</option>--%>
                    <%--<option value="option3">数码产品</option>--%>
                    <%--<option value="option3">笔记本电脑</option>--%>
                    <%--<option value="option3">平板电脑</option>--%>
                    <%--<option value="option3">只能手机</option>--%>
                    <%--<option value="option3">超极本</option>--%>
                </select>
            </div>

            <div class="am-u-sm-9 am-u-lg-10 modal-input-div">

            </div>
            <button type="button" id="addBtnpro" class=" am-u-md-12  am-btn am-btn-primary" style="margin-top: 10px">添加
            </button>
        </div>
    </div>


    <script src="/resources/js/amazeui.min.js"></script>
    <script src="/resources/js/amazeui.datatables.min.js"></script>
    <script src="/resources/js/dataTables.responsive.min.js"></script>
    <script src="/resources/js/app.js"></script>
    <script>
        function getPermisson(id) {
            var url = "/pro/getemptype";
            var meunid = $('#menuId');
            meunid.val(id);
            $.ajax({
                url: url,
                type: 'POST',
                cache: false,
                processData: false,
                contentType: false
            }).done(function (res) {
                if (res === null || res === undefined || res === '') {
                    alert("服务器内部错误，请刷新重试");
                    return;
                }
                var menuslect = $('#menudetali');
                menuslect.empty();
                var optionString = "";
                for (var i = 0; i < res.length; i++) {
                    optionString += '<option value="' + res[i].emTypeId + '">' + res[i].typeInstruct + '</option>';
                }
                menuslect.append(optionString);
            }).fail(function () {
                alert("网络错误,请刷新重试");
            });
            $("#promission-type-model").modal();
        }

        $("#addBtnpro").click(function () {
            var menuId = $('#menuId').val();
            var etid = $('#menudetali').val();
            if (etid === null || etid === undefined || etid === '' || menuId === null || menuId === undefined || menuId === '') {
                alert("数据异常，请刷新页面重试");
                return;
            }
            var formData = new FormData();
            formData.append('eid', etid);
            formData.append('menuId', menuId);
            var url = "/pro/InsertMeuid";
            $.ajax({
                url: url,
                type: 'POST',
                cache: false,
                data: formData,
                processData: false,
                contentType: false
            }).done(function (res) {
                console.log(res);
                if (res === null || res === undefined || res === '') {
                    alert("服务器错误,请检查数据或者刷新页面重试");
                    return;
                }
                alert(res.data);
                window.location.reload();
                //  return res;
            }).fail(function (res) {
                console.log(res);
                alert("网络错误，请检查数据或者刷新页面重试");
            });

        });

        //更新订单状态
        function updateType(id,status) {
            $("#fristName").css("borderStyle", "");
            $("#fristName").css("borderColor", "");
            $("#fristName").css("borderWidth", "");
            var formData = new FormData();
            formData.append("id", id);
            formData.append("status", status);
            var url = "/stockManageController/updateApplication";
            $.ajax({
                url: url,
                type: 'post',
                cache: false,
                data: formData,
                processData: false,
                contentType: false
            }).done(function (res) {
                if (res === null || res === undefined || res === '') {
                    alert("网络开小差了");
                    return;
                }
                console.log(res);

                if (res.success){
                    alert("更新成功");
                    window.location.reload();
                } else {
                    alert(res.result);
                }

            }).fail(function (res) {
                console.log(res);
                alert("网络开小差了")

            });
        }





        function editType(id) {
            $("#fristName").css("borderStyle", "");
            $("#fristName").css("borderColor", "");
            $("#fristName").css("borderWidth", "");
            var formData = new FormData();
          //  formData.append("id", id);
            var url = "/stockManageController/haveApplication?id="+id;
            $.ajax({
                url: url,
                type: 'get',
                cache: false,
            //    data: formData,
                processData: false,
                contentType: false
            }).done(function (res) {
                if (res === null || res === undefined || res === '') {
                    alert("网络开小差了11");
                    return;
                }
                console.log(res);
                alert("更新成功");
                window.location.reload();
              /*  $("#fristIconDiv").empty();
                var modal = $('#type-model');
                $("#fristid").val(res.id);
                $("#fristName").val(res.name);
                $("#fristicon").val(res.icon);
                var icon = "<i class=\"" + res.icon + "  sidebar-nav-link-logo am-icon-md\"></i>";
                $("#fristIconDiv").append(icon);*/
             //   modal.modal({'width': '600'});
            }).fail(function (res) {
                console.log(res);
                alert("网络开小差了22")

            });
        }

        $('#fristAddBtn').click(function () {
            var id = $("#fristid").val();
            var name = $("#fristName").val();
            var icon = $("#fristicon").val();

            if (!checkName(name)) {
                alert("请检查输入的数据");
                return;
            }
            if (id === null || id === undefined || id === '') {
                alert("请检查输入的数据");
                return;
            }
            var formData = new FormData();
            formData.append("id", id);
            formData.append("name", name);
            formData.append("icon", icon);
            var url = "/m/update";
            $.ajax({
                url: url,
                type: 'POST',
                cache: false,
                data: formData,
                processData: false,
                contentType: false
            }).done(function (res) {
                if (res === null || res === undefined || res === '') {
                    alert("网络开小差了");
                    return;
                }
                console.log(res);
                window.location.reload();
                alert(res.data);

            }).fail(function (res) {
                console.log(res);
                alert("网络开小差了");
            });

        });

        function seeMenu(purid) {
            var secondTable = $("#secondTable");
            secondTable.show();
            var bodyTable = $("#secondTable tbody");
            var formData = new FormData();
            formData.append("purid", purid);
            var url = "/stockManageController/getlist";
            var tableString = "";
            $.ajax({
                url: url,
                type: 'POST',
                cache: false,
                data: formData,
                processData: false,
                contentType: false
            }).done(function (res) {
                if (res === null || res === undefined || res === '') {
                    alert("网络开小差了");
                    return;
                }
                console.log(res);
                bodyTable.empty();
                for (var i = 0; i < res.length; i++) {
                    var str = res[i].proStock > res[i].amount ? "可以发货" : "需要补充货源";
                    var thtd = " <tr><td>" + (i + 1) + "</td>\n" +
                        "<td>" + res[i].pname + "</td>" +
                        "<td>" + res[i].sumPrice + "</td>\n" +
                        "<td>" + res[i].purchasePrice + "&nbsp;元//" + res[i].measureWay + "</td>\n" +
                        "<td>" + res[i].proStock + res[i].measureWay + "</td>\n" +
                        "<td>" + res[i].amount + res[i].measureWay + "</td>\n" +
                        "<td>\n" + str +
                        "</td>\n" +
                        "</tr>";
                    console.log(thtd);
                    tableString += thtd;
                }
                // console.log(tableString);
                bodyTable.append(tableString);
            }).fail(function (res) {
                console.log(res);
                alert("网络开小差了")

            });
        }

        function hiddenMenu() {
            $("#secondTable").hide();
        }

        function editChildType(pid) {
            $("#secondeName").css("borderStyle", "");
            $("#secondeName").css("borderColor", "");
            $("#secondeName").css("borderWidth", "");
            $("#secondeName").focus();
            var formData = new FormData();
            formData.append("id", pid);
            var url = "/m/getOne";
            $.ajax({
                url: url,
                type: 'POST',
                cache: false,
                data: formData,
                processData: false,
                contentType: false
            }).done(function (res) {
                if (res === null || res === undefined || res === '') {
                    alert("网络开小差了");
                    return;
                }
                console.log(res);
                var modal = $('#seconde-type-model');
                $("#secondeId").val(res.id);
                $("#secondeName").val(res.name);
                $("#secondeUrl").val(res.href);
                modal.modal({'width': '600'});
            }).fail(function (res) {
                console.log(res);
                alert("网络开小差了");
            });

        }

        function updateSecondMenu() {
            var id = $("#secondeId").val();
            var name = $("#secondeName").val();
            if (!checkName(name)) {
                alert("请检查输入的数据");
                return;
            }
            var formData = new FormData();
            formData.append("id", id);
            formData.append("name", name);
            var url = "/m/update";
            $.ajax({
                url: url,
                type: 'POST',
                cache: false,
                data: formData,
                processData: false,
                contentType: false
            }).done(function (res) {
                if (res === null || res === undefined || res === '') {
                    alert("网络开小差了");
                    return;
                }
                console.log(res);
                window.location.reload();
                alert(res.data);

            }).fail(function (res) {
                console.log(res);
                alert("网络开小差了");
            });
        }

        $("#fristName").change(function () {
            var name = $("#fristName").val();
            if (checkName(name)) {
                $("#fristName").css("borderStyle", "");
                $("#fristName").css("borderColor", "");
                $("#fristName").css("borderWidth", "");
            } else {
                $("#fristName").css("borderStyle", "solid");
                $("#fristName").css("borderColor", "red");
                $("#fristName").css("borderWidth", "1px");
                $("#fristName").focus();
            }
        });


        $("#secondeName").change(function () {
            var name = $("#secondeName").val();
            if (checkName(name)) {
                $("#secondeName").css("borderStyle", "");
                $("#secondeName").css("borderColor", "");
                $("#secondeName").css("borderWidth", "");
            } else {
                $("#secondeName").css("borderStyle", "solid");
                $("#secondeName").css("borderColor", "red");
                $("#secondeName").css("borderWidth", "1px");
                $("#secondeName").focus();
            }
        });

        function checkName(name) {
            //校验是否是中文
            var tireg = /^[\u2E80-\u9FFF]+$/;
            if ((tireg.test(name)) && name.length < 20) {
                return true;
            }
            return false;
        }

        $("#fristicon").change(function () {
            $("#fristIconDiv").empty();
            var iconString = $("#fristicon").val();
            var icon = "<i class=\"" + iconString + "  sidebar-nav-link-logo am-icon-md\"></i>";
            $("#fristIconDiv").append(icon);
        });
    </script>

</body>

</html>
